import Vue from "vue";
import VueRouter from "vue-router";
import store from "@/store";

Vue.use(VueRouter);

const routes = [{
    path: "/",
    name: "login",
    component: () => import("@/views/Login"),
    meta: {
      title: "登录"
    }
  },
  {
    path: "/decoration/pc",
    name: "PersonalComputer",
    component: () => import("@/views/childComps/decoration/PersonalComputer"),
    meta: {
      title: "电脑端装修"
    }
  },
  {
    path: "/decoration/h5",
    name: "mobile",
    component: () => import("@/views/childComps/decoration/Mobile"),
    meta: {
      title: "移动端装修"
    }
  },
  {
    path: "/home",
    name: "home",
    component: () => import("@/views/Home"),
    children: [{
        path: "/dashboard",
        component: () => import("@/views/childComps/dashboard/View"),
        children: [
          {
            path: "/",
            component: () => import("@/views/childComps/dashboard/Dashboard"),
            meta: {
              title: "MeEdu后台管理"
            }
          },
          {
            path: "/administrator/change-password",
            component: () => import("@/views/childComps/dashboard/ChangePwd"),
            meta: {
              title: "修改密码"
            }
          }
        ]
      },
      {
        path: '/course/vod/index',
        component: () => import('@/views/childComps/course/CourseView'),
        children: [
          {
            path: "/",
            component: () => import('@/views/childComps/course/Vod'),
            meta: {
              title: "录播课"
            }
          },
          {
            path: "/course/vod/create",
            component: () => import('@/views/childComps/course/Create'),
            meta: {
              title: "新建录播课程"
            }
          },
          {
            path: "/course/vod/video/index",
            component: () => import('@/views/childComps/course/VodManagement'),
            meta: {
              title: "课时管理"
            }
          },
          {
            path: "/course/vod/video/create",
            component: () => import('@/views/childComps/course/VodCreateVideo'),
            meta: {
              title: "添加课时"
            }
          },
          {
            path: "/course/vod/update",
            component: () => import('@/views/childComps/course/VodUpdate'),
            meta: {
              title: "编辑录播课程"
            }
          },
          {
            path: "/course/vod/attach/index",
            component: () => import('@/views/childComps/course/VodAttach'),
            meta: {
              title: "课程附件管理"
            }
          },
          {
            path: "/course/vod/category/index",
            component: () => import('@/views/childComps/course/Category'),
            meta: {
              title: "课程分类管理"
            }
          },
          {
            path: "/course/vod/category/create",
            component: () => import('@/views/childComps/course/CategoryCreate'),
            meta: {
              title: "添加课程分类"
            }
          },
          {
            path: "/course/vod/category/update",
            component: () => import('@/views/childComps/course/CategoryUpdate'),
            meta: {
              title: "编辑课程分类"
            }
          },
          {
            path: "/course/vod/components/vod-comments",
            component: () => import('@/views/childComps/course/VodComments'),
            meta: {
              title: "课程评论"
            }
          },
          {
            path: "/course/vod/video/comments",
            component: () => import('@/views/childComps/course/VideoComments'),
            meta: {
              title: "课时评论"
            }
          },
          {
            path: "/course/vod/video-import",
            component: () => import('@/views/childComps/course/VideoImport'),
            meta: {
              title: "视频批量导入"
            }
          }
        ]
      },
      {
        path: '/member/index',
        component: () => import('@/views/childComps/member/MemberView'),
        children: [{
            path: '/',
            component: () => import('@/views/childComps/member/Member'),
            meta: {
              title: '学员列表'
            },
          },
          {
            path: '/member/create',
            component: () => import('@/views/childComps/member/CreateView.vue'),
            meta: {
              title: '添加学员'
            }
          },
          {
            path: '/member/import',
            component: () => import("@/views/childComps/member/ImportView.vue"),
            meta: {
              title: '学员批量导入'
            }
          },
          {
            path: '/member/profile',
            component: () => import('@/views/childComps/member/ProfileView.vue'),
            meta: {
              title: '实名信息',
            }
          },
          {
            path: '/member/:id',
            component: () => import("@/views/childComps/member/UserMember.vue"),
            meta: {
              title: '学员详情'
            }
          },
          {
            path: '/member/:id/edit',
            component: () => import("@/views/childComps/member/EditView.vue"),
            meta: {
              title: '编辑学员',
            }
          },
          {
            path: '/member/:id/credit',
            component: () => import("@/views/childComps/member/creditView.vue"),
            meta: {
              title: '学员积分',
            }
          },
          {
            path: '/member/:id/tags',
            component: () => import("@/views/childComps/member/tagsView.vue"),
            meta: {
              title: '学员积分',
            }
          },
        ]
      },
      {
        path: '/order/index',
        component: () => import('@/views/childComps/finance/Order'),
        children: [{
            path: '/',
            component: () => import('@/views/childComps/finance/AllOrder'),
            meta: {
              title: '全部订单'
            }
          },
          {
            path: '/order/refund',
            component: () => import('@/views/childComps/finance/Refund'),
            meta: {
              title: '退款订单'
            }
          },
          {
            path: '/order/looktext',
            component: () => import("@/views/childComps/finance/LookText"),
            meta: {
              title: '订单详情'
            }
          }
        ]
      },
      {
        path: "/withdrawOrders",
        component: () => import("@/views/childComps/finance/WithdrawOrder"),
        meta: {
          title: "余额提现"
        }
      },
      {
        path: "/role",
        component: () => import("@/views/childComps/operate/View"),
        children: [
          {
            path: "/",
            component: () => import("@/views/childComps/operate/Role"),
            meta: {
              title: "VIP会员"
            }
          },
          {
            path: "/addrole",
            component: () => import("@/views/childComps/operate/AddRole"),
            meta: {
              title: "VIP会员"
            }
          },
          {
            path: "/editrole",
            component: () => import("@/views/childComps/operate/EditRole"),
            meta: {
              title: "VIP会员"
            }
          },
          {
            path: "/promocode",
            component: () => import("@/views/childComps/operate/Promocode"),
            meta: {
              title: "优惠码"
            }
          },
          {
            path: "/createcode",
            component: () => import("@/views/childComps/operate/CreateCode"),
            meta: {
              title: "添加优惠码"
            }
          },
          {
            path: "/order/code-import",
            component: () => import("@/views/childComps/operate/ImportCode"),
            meta: {
              title: "优惠码批量导入"
            }
          },
          {
            path: "/createmulticode",
            component: () => import("@/views/childComps/operate/MultiCode"),
            meta: {
              title: "优惠码批量生成"
            }
          },
          {
            path: "/wechat/messagereply/index",
            component: () => import("@/views/childComps/operate/OfficialAccount"),
            meta: {
              title: "公众号"
            }
          },
          {
            path: "/wechat/messagereply/create",
            component: () => import("@/views/childComps/operate/CreateAutoReply"),
            meta: {
              title: "新建自动回复"
            }
          },
          {
            path: "/wechat/messagereply/update",
            component: () => import("@/views/childComps/operate/EditAutpReply"),
            meta: {
              title: "编辑自动回复"
            }
          }
        ]
      },
      {
        path: '/system/administrator',
        component: () => import('@/views/childComps/system/View'),
        children: [
          {
            path: '/',
            component: () => import('@/views/childComps/system/Administrator'),
            meta: {
              title: '管理人员'
            }
          },
          {
            path: '/system/index',
            component: () => import('@/views/childComps/system/System'),
            meta: {
              title: '系统配置'
            }
          },
          {
            path: '/system/application',
            component: () => import('@/views/childComps/system/Application'),
            meta: {
              title: '功能模块'
            }
          },
          {
            path: '/system/administrator/create',
            component: () => import('@/views/childComps/system/AddAdministrator'),
            meta: {
              title: '添加管理员'
            }
          },
          {
            path: '/system/administrator/update',
            component: () => import('@/views/childComps/system/EditAddAdministrator'),
            meta: {
              title: '编辑管理员'
            }
          }
        ]
      }
    ]
  }
];

const router = new VueRouter({
  routes
});

router.beforeEach((to, from, next) => {
  store.dispatch("updateToken");
  if (!store.state.user.isLogin && to.path !== "/") return next({
    path: "/"
  });
  if (store.state.user.isLogin && to.path === "/") return next({
    path: "/dashboard"
  });
  next();
  document.title = to.meta.title;
});

export default router;